package ch.lue.tvsedit.model;

import java.util.ArrayList;

import javax.swing.AbstractListModel;

public class ChannelGroup extends AbstractListModel
{
	private ArrayList<String> channels = new ArrayList<String>();
	
	private String name;
	private int position;
	
	public ChannelGroup(String name, int pos) 
	{
		this.name = name;
		this.position = pos;
	}

	public void addChannel(String name, int position)
	{
		if(channels.contains(name))
			return;
		
		if(position < channels.size())
		{
			channels.add(position, name);
			fireIntervalAdded(this, position,  position);
		}
		else
		{
			channels.add(name);
			fireIntervalAdded(this, channels.size()-1,  channels.size()-1);
		}
	}
	
	public void moveUp(int index) 
	{
		String t = channels.get(index);
		channels.add(index-2, t);
		channels.remove(index);
		fireContentsChanged(this, index-2, index);
	}

	@Override
	public Object getElementAt(int index) {
		return channels.get(index);
	}

	@Override
	public int getSize() {
		return channels.size();
	}

	public Object getName() {
		return name;
	}

	public String getDisplayName() {
		return name;
	}

	public void addChannel(String name) 
	{
		addChannel(name, channels.size());
	}
}
